<template>
	<view class="box">
		<view class="header">
			<view class="left" @click="gohome">
				<image src="https://s1.ax1x.com/2022/12/02/zBZYkQ.jpg" mode=""></image>
				返回
			</view>
			<view class="center">
				生活缴费
			</view>
			<view class="right" @click="gorecord">
				缴费记录
			</view>
		</view>
		<view class="top">
			<view class="plot">
				<picker :range="buildingName" :range-key="'building'" @change="getfeeList">
					<view>{{name}}
						<image src="https://s1.ax1x.com/2022/12/02/zDCsL4.png" mode=""></image>
					</view>
				</picker>
			</view>
			<view class="pirce">
				应缴费:{{priceSum}}元
				<view class="btu">
					缴 费
				</view>
			</view>
		</view>
		<view class="list" v-for="(item,index) in list" :key="index">
			<view class="name">
				物业费账单
			</view>
			<view class="houseno">
				<view class="left">
					房号
				</view>
				<view class="right">
					{{item.houseno}}
				</view>
			</view>
			<view class="houseno">
				<view class="left">
					账单
				</view>
				<view class="right">
					{{item.begindate}} 至 {{item.enddate}}
				</view>
			</view>
			<view class="houseno">
				<view class="left">
					账单金额
				</view>
				<view class="right">
					{{item.price}}元
				</view>
			</view>
		</view>
		<view class="btm">

		</view>
	</view>
</template>

<script>
	import {
		feelist,
		houseCheck
	} from "pages/utils/api.js"
	export default {
		data() {
			return {
				searchData: {
					page: 1,
					psize: 5,
					houseid: [] // 房间id
				},
				list: [],
				name: '请选择房间号',
				buildingName: [], //楼栋
				feeData: {
					building: '',
					details: []
				},
				houselist: []
			}
		},
		async onLoad() {
			await this.getfeelist()
			this.gethouseCheck()
		},
		methods: {
			async gethouseCheck() {
				let res = await houseCheck()
				console.log(res);
				if (res.errCode == 10000) {
					res.data.list.map(item => {
						this.searchData.houseid = [...this.searchData.houseid, item.houseid]
						this.buildingName = [...this.buildingName, item.building]
					})
					this.houselist = res.data.list
				}
			},
			async getfeelist() {
				console.log(this.searchData);
				let res = await feelist(this.searchData)
				console.log(res);
				this.list = res.data.list
				this.feeData.details = this.list.map(item => {
					return {
						feeid: item.id
					}
				})
			},
			getfeeList(e) {
				this.name = this.houselist[e.detail.value].building
				this.houseid = this.houselist[e.detail.value].houseid

			},
			gohome() {
				uni.switchTab({
					url: '../home'
				})
			},
			gorecord() {
				uni.navigateTo({
					url: `./Record/Record?feeData=${JSON.stringify(this.feeData)}&price=${this.priceSum}`
				})
			}
		},
		computed: {
			priceSum() {
				return this.list.reduce((pre, cur, index, arr) => cur.price + pre, 0).toFixed(2)
			}
		},
	}
</script>

<style lang="less">
	.box {
		width: 100%;
		background-color: #f0f0f0;

		.header {
			width: 730rpx;
			height: 135rpx;
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 10rpx;
			font-size: 26rpx;

			.left {
				display: flex;

				image {
					width: 26rpx;
					height: 25rpx;
					display: block;
					margin-top: 6rpx;
				}

			}

			.center {
				margin-left: 50rpx;
			}

			.right {
				color: #0080fe;
			}
		}

		.top {
			width: 730rpx;
			height: 435rpx;
			margin-left: 10rpx;

			.plot {
				width: 100%;
				height: 105rpx;
				line-height: 105rpx;
				font-size: 30rpx;

				// padding: 0 15rpx;
				image {
					width: 30rpx;
					height: 17rpx;
				}
			}

			.pirce {
				width: 100%;
				height: 330rpx;
				background-image: url("https://s1.ax1x.com/2022/12/02/zBniyq.png");
				background-size: 100%;
				text-align: center;
				line-height: 200rpx;
				font-size: 40rpx;
				color: #fff;

				.btu {
					width: 288rpx;
					height: 85rpx;
					background-color: #fff;
					line-height: 85rpx;
					color: #26a9f2;
					border-radius: 50rpx;
					margin-left: 220rpx;
					font-size: 32rpx;
				}
			}
		}

		.btm {
			width: 100%;
			height: 200rpx;

		}
	}

	.list {
		width: 730rpx;
		height: 328rpx;
		background-color: #fff;
		border-radius: 15rpx;
		margin-left: 10rpx;
		margin-top: 20rpx;

		.name {
			width: 657rpx;
			height: 79rpx;
			border-bottom: 1rpx solid #eeeeee;
			margin-left: 40rpx;
			line-height: 79rpx;
			font-size: 26rpx;
		}

		.houseno {
			width: 657rpx;
			margin-left: 40rpx;
			margin-top: 40rpx;
			font-size: 26rpx;
			display: flex;
			justify-content: space-between;
		}
	}
</style>
